package com.bingfor.easycablelink.widgets;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;

import com.bingfor.easycablelink.base.BaseActivity;
import com.bingfor.easycablelink.databinding.DialogShareBinding;
import com.bingfor.easycablelink.utils.ShareUtils;
import com.bingfor.easycablelink.utils.ToastUtil;
import com.umeng.socialize.Config;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.QQExtra;

public class ShareDialog extends Activity {

    DialogShareBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DialogShareBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        getWindow().setLayout(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT);
        initView();
    }

    private void initView() {
        binding.tvCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        binding.toShareQq.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              boolean flag =   UMShareAPI.get(ShareDialog.this).isInstall(ShareDialog.this, SHARE_MEDIA.QQ);
                if (flag){
                    ShareUtils.QqShare(ShareDialog.this, "http://www.baidu.com", umShareListener);
                }else {
                    ToastUtil.showToast(ShareDialog.this,"请下载安装QQ后进行分享.");
                }
            }
        });
        binding.toShareQqZone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                boolean flag =   UMShareAPI.get(ShareDialog.this).isInstall(ShareDialog.this, SHARE_MEDIA.QZONE);
                if (flag){
                    ShareUtils.QqZoneShare(ShareDialog.this, "http://www.baidu.com", umShareListener);
                }else {
                    ToastUtil.showToast(ShareDialog.this,"请下载安装QQ后进行分享.");
                }

            }
        });
        binding.toShareWeixin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                boolean flag =   UMShareAPI.get(ShareDialog.this).isInstall(ShareDialog.this, SHARE_MEDIA.WEIXIN);
                if (flag){
                    ShareUtils.WeixinShare(ShareDialog.this, "http://www.baidu.com", umShareListener);
                }else {
                    ToastUtil.showToast(ShareDialog.this,"请下载安装微信后进行分享.");
                }

            }
        });
        binding.toShareWeixinCirlce.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                boolean flag =   UMShareAPI.get(ShareDialog.this).isInstall(ShareDialog.this, SHARE_MEDIA.WEIXIN_CIRCLE);
                if (flag){
                    ShareUtils.WeixinCircleShare(ShareDialog.this, "http://www.baidu.com", umShareListener);
                }else {
                    ToastUtil.showToast(ShareDialog.this,"请下载安装微信后进行分享.");
                }

            }
        });
    }
    UMShareListener umShareListener = new UMShareListener() {
        @Override
        public void onStart(SHARE_MEDIA share_media) {
            ToastUtil.showToast(ShareDialog.this, "开始分享.");
        }

        @Override
        public void onResult(SHARE_MEDIA share_media) {
            ToastUtil.showToast(ShareDialog.this, "分享成功.");
        }

        @Override
        public void onError(SHARE_MEDIA share_media, Throwable throwable) {
            ToastUtil.showToast(ShareDialog.this, "分享失败.");
        }

        @Override
        public void onCancel(SHARE_MEDIA share_media) {
            ToastUtil.showToast(ShareDialog.this, "取消分享.");
        }
    };
}